package Views.TableModels;

import Models.*;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

/**
 * @author Morten
 */
public class MachineTableModel extends DefaultTableModel
{
	ArrayList<Machine> machines;

	public MachineTableModel()
	{
		this.machines = new ArrayList<Machine>();
	}

	public MachineTableModel(ArrayList<Machine> machines)
	{
		this.machines = machines;
	}

		@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}

	public void setData(ArrayList<Machine> machines)
	{
		this.machines = machines;
		fireTableDataChanged();
	}

	public ArrayList<Machine> getData()
	{
		return this.machines;
	}

	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public int getRowCount()
	{
		if(this.machines == null)
		{
			return 0;
		}
		else
		{
			return this.machines.size();
		}
	}

	@Override
	public String getColumnName(int column) {
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "ID";
				break;
			case 1:
				columnName = "Navn";
				break;
			case 2:
				columnName = "Tilgængelig";
				break;

		}
		return columnName;
	}



	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.machines.get(row).getId();
				break;
			case 1:
				value = this.machines.get(row).getName();
				break;
			case 2:
				if(this.machines.get(row).isAvailable() == true)
				{
					value = "Ja";
				}
				else
				{
					value = "Nej";
				}
				break;

		}

		return value;
	}
}